﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_FIT_WEIGHT_TRAINING_Change_Training_Id')
	BEGIN
		DROP Procedure usp_UPDMS_FIT_WEIGHT_TRAINING_Change_Training_Id
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_FIT_WEIGHT_TRAINING_Change_Training_Id
**	Desc : 트레이닝아이디 변경
**	Test Exec Query : Exec usp_UPDMS_FIT_WEIGHT_TRAINING_Change_Training_Id 'TR00000227', 'TR00000228', 'smstyle'
**	Called by : Fit_Dac_UPDMS_FIT_FIGURE_MGT.cs
**	Program ID : Fit1011m
**	Auth : 송시명
**	Date : 2015-01-12
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_FIT_WEIGHT_TRAINING_Change_Training_Id]
@asis_training_id nvarchar(10),
@tobe_training_id nvarchar(10),
@ls_user_id nvarchar(20)
AS
SET NOCOUNT OFF

--(asis -> other)
UPDATE UPDMS_FIT_WEIGHT_TRAINING
   SET Training_Id = 'TRXXXXXXXX'
 WHERE Training_Id = @asis_training_id


--(tobe -> asis)
UPDATE UPDMS_FIT_WEIGHT_TRAINING
   SET Training_Id = @asis_training_id,
       Update_User = @ls_user_id,
       Update_Dt = GETDATE()
 WHERE Training_Id = @tobe_training_id


--(other -> tobe)
UPDATE UPDMS_FIT_WEIGHT_TRAINING
   SET Training_Id = @tobe_training_id,
       Update_User = @ls_user_id,
       Update_Dt = GETDATE()
 WHERE Training_Id = 'TRXXXXXXXX'


--(asis -> other)
UPDATE UPDMS_FIT_WEIGHT_TRAINING_PARTS
   SET Training_Id = 'TRXXXXXXXX'
 WHERE Training_Id = @asis_training_id


--(tobe -> asis)
UPDATE UPDMS_FIT_WEIGHT_TRAINING_PARTS
   SET Training_Id = @asis_training_id,
       Update_User = @ls_user_id,
       Update_Dt = GETDATE()
 WHERE Training_Id = @tobe_training_id


--(other -> tobe)
UPDATE UPDMS_FIT_WEIGHT_TRAINING_PARTS
   SET Training_Id = @tobe_training_id,
       Update_User = @ls_user_id,
       Update_Dt = GETDATE()
 WHERE Training_Id = 'TRXXXXXXXX'

GO